package com.example.lxj.archives.controller;

import java.util.List;
import java.util.Optional;

import com.example.lxj.archives.entity.TbArchiveBorrowReturns;
import com.example.lxj.base.annoation.Permission;
import com.example.lxj.base.controller.BaseController;
import com.example.lxj.base.entity.AjaxRes;
import com.example.lxj.base.entity.PageDTO;
import com.example.lxj.base.entity.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.lxj.archives.service.ITbArchiveBorrowReturnsService;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 档案借阅与归还Controller
 *
 * @author lxj
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/archives/bt")
public class TbArchiveBorrowReturnsController extends BaseController {
    @Autowired
    private ITbArchiveBorrowReturnsService tbArchiveBorrowReturnsService;

    /**
     * 查询档案借阅与归还列表
     */
    @Permission(value = "archives:bt:list")
    @GetMapping("/list")
    public TableDataInfo list(TbArchiveBorrowReturns tbArchiveBorrowReturns, PageDTO pageDTO) {
        startPage(Optional.ofNullable(pageDTO.getPageNo()).orElse(1), Optional.ofNullable(pageDTO.getPageSize()).orElse(10));
        List<TbArchiveBorrowReturns> list = tbArchiveBorrowReturnsService.selectTbArchiveBorrowReturnsList(tbArchiveBorrowReturns);
        return getDataTable(list);
    }

    /**
     * 获取档案借阅与归还详细信息
     */
    @Permission(value = "archives:bt:query")
    @GetMapping(value = "/{id}")
    public AjaxRes getInfo(@PathVariable("id") Long id) {
        return success(tbArchiveBorrowReturnsService.selectTbArchiveBorrowReturnsById(id));
    }

    /**
     * 新增档案借阅与归还
     */
    @Permission(value = "archives:bt:add")
    @PostMapping
    public AjaxRes add(@RequestBody TbArchiveBorrowReturns tbArchiveBorrowReturns) {
        return toAjax(tbArchiveBorrowReturnsService.insertTbArchiveBorrowReturns(tbArchiveBorrowReturns));
    }

    /**
     * 修改档案借阅与归还
     */
    @Permission(value = "archives:bt:edit")
    @PutMapping
    public AjaxRes edit(@RequestBody TbArchiveBorrowReturns tbArchiveBorrowReturns) {
        return toAjax(tbArchiveBorrowReturnsService.updateTbArchiveBorrowReturns(tbArchiveBorrowReturns));
    }

    /**
     * 删除档案借阅与归还
     */
    @Permission(value = "archives:bt:remove")
    @DeleteMapping("/{id}")
    public AjaxRes remove(@PathVariable("id") Long id) {
        return toAjax(tbArchiveBorrowReturnsService.deleteTbArchiveBorrowReturnsById(id));
    }
}
